<template>
    <div>
      <table>
        <tr>
          <td>商品名称</td>
          <td><input type="text" v-model="name"></td>
        </tr>
        <tr>
          <td>商品价格</td>
          <td><input type="text" v-model="price"></td>
        </tr>
        <tr>
          <td>商品标签</td>
          <td><TagInput v-model="mytags" type="string" split="," placeholder="输入标签，英文逗号分隔，输入完毕回车确认"></TagInput></td>
        </tr>
        <button @click="add">添加</button>
      </table>
    </div>
</template>

<script>
    export default {
        name: "addgos",
      data:function () {
        return{
          name:'',
          price:'',
          mytags:'',
          cate_id:1,
        }
      },
      methods:{
          add:function () {
            // 发送请求
            this.axios.get(
              'http://127.0.0.1:8000/insertgoods/',{params:{name:this.name, price:this.price,cate_id:this.cate_id}}).then(res=>{
                console.log(res);
                this.$Message(res.data.msg);

              // 只有商品入库成功才能添加标签
              if(res.data.id) {
                // 标签分类嵌套发送请求    id是商品ID  联动添加
                this.axios.get(
                  'http://127.0.0.1:8000/inserttags/', {params: {id: res.data.id, tags: this.mytags}}).then(res => {
                  console.log(res);
                });
              }
            });

          }

      }
    }
</script>

<style scoped>

</style>
